import React from 'react';
import { Provider } from 'mobx-react';
import New from './new/New';
import { WeaDialog, WeaLocaleProvider } from 'ecCom';
import stores from '../stores';

const { getLocaleLabelByCode } = WeaLocaleProvider;
const getLabel = WeaLocaleProvider.getLabel;
class emailNewForDialog extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      reRender: false,
      // visible: false
    };
  }

  componentDidMount() {
    // 多语言加载之后，已经 mount 的组件，需要重新 render 一次，刷新多语言配置。
    getLocaleLabelByCode('email').then(() =>
      this.setState({
        reRender: true,
      }),
    );
  }

  onCancel = () => {
    this.setState({ visible: false }, () => {
      stores.emailNewStore.clear();
      this.props.onCancel && this.props.onCancel();
    });
  };

  render() {
    return (
      <Provider
        ecId={`${
          (this && this.props && this.props.ecId) || ''
        }_Provider@pxhzy6`}
        {...stores}
      >
        <WeaDialog
          ecId={`${
            (this && this.props && this.props.ecId) || ''
          }_WeaDialog@qsvg80`}
          title={getLabel(81300, '写信')}
          style={{ width: 900, height: 600 }}
          visible={this.props.visible}
          onCancel={this.onCancel}
        >
          <New
            ecId={`${(this && this.props && this.props.ecId) || ''}_New@28bf6u`}
            {...this.props}
            location={{ query: {} }}
          />
        </WeaDialog>
      </Provider>
    );
  }
}

export default emailNewForDialog;
